"""
多智能体项目管理系统 - 主代理模块
本模块定义了项目协调代理(root_agent)，负责协调整个项目管理生命周期
"""

import os
from google.adk.agents import LlmAgent
from google.adk.tools.agent_tool import AgentTool
from google.adk.models.lite_llm import LiteLlm
from .task_definition_agent import task_definition_agent  # 导入任务定义代理
from .task_assignment_agent import task_assignment_agent  # 导入任务分配代理
from .progress_tracking_agent import progress_tracking_agent  # 导入进度跟踪代理


# 创建工具列表，将子智能体包装为工具
# 任务定义工具 - 负责将项目目标分解为具体任务
task_definition_tool = AgentTool(agent=task_definition_agent)

# 任务分配工具 - 负责将任务分配给合适的团队成员
task_assignment_tool = AgentTool(agent=task_assignment_agent)

# 进度跟踪工具 - 负责生成项目进度报告和状态摘要
progress_tracking_tool = AgentTool(agent=progress_tracking_agent)

# API密钥配置
DEFAULT_DASHSCOPE_API_KEY = "sk-f227634bb56*************************232"  # 请替换为您的实际密钥
DASHSCOPE_API_KEY = os.environ.get("DASHSCOPE_API_KEY", DEFAULT_DASHSCOPE_API_KEY)

# 根据ADK文档要求，定义root_agent（项目协调代理）
# 这是整个系统的核心代理，负责协调其他专门的子代理
root_agent = LlmAgent(
    name="ProjectCoordinatorAgent",  # 代理名称：项目协调代理
    model=LiteLlm(
                model="openai/qwen-turbo",  # 使用通义千问Turbo模型
                api_key=DASHSCOPE_API_KEY,
                api_base="https://dashscope.aliyuncs.com/compatible-mode/v1"
    ),
    instruction="""
    You are a Project Coordinator. Your goal is to manage a project based on the user's input project goal.
    Follow these steps meticulously:
    1. Acknowledge the user's project goal.
    2. Use the 'TaskDefinitionAgent' tool to break down the project goal into specific tasks. The user's original goal should be passed as 'user_input' to this tool.
    3. Present the defined tasks to the user.
    4. Use the 'TaskAssignmentAgent' tool to assign these defined tasks. The output from 'TaskDefinitionAgent' (the list of tasks) should be passed as 'tasks_to_assign' to this tool.
    5. Inform the user about the (simulated) task assignments.
    6. Simulate some time passing and tasks being worked on. Provide a placeholder update like "Team is now working on the assigned tasks. Progress will be updated shortly."
    7. Use the 'ProgressTrackingAgent' tool to generate a project summary. For simulation, provide it with a generic update string like "Task 1 (from the defined list) is 60% complete, Task 2 is 30% complete, other tasks are starting." This update should be passed as 'simulated_updates' to the tool.
    8. Present the final project summary to the user.

    The user's initial message will contain the project goal.
    Ensure your responses are clear, follow the steps, and explicitly mention when you are using a tool and what its output is.
    """,
    tools=[task_definition_tool, task_assignment_tool, progress_tracking_tool],  # 配置可用的工具列表
    description="Coordinates the entire project management lifecycle from goal to status reporting using specialized sub-agents."  # 代理描述
) 